#include <sys/epoll.h>
#include <memory.h>
#include <unistd.h>
#include <iostream>
#include <string>
int main()
{
    
    
    int efd=epoll_create1(0);

    // epoll_event event;
    // event.events|=(EPOLLIN);

    epoll_event event1;
    event1.events|=EPOLLOUT;
    
    //epoll_ctl(efd,EPOLL_CTL_ADD,0,&event);
     epoll_ctl(efd,EPOLL_CTL_ADD,1,&event1);

    epoll_event temp;
    int count=0;
    
    std::cout<<"开始"<<std::endl;
    while(1)
    {
        std::cout<<"开始等待"<<std::endl;
        epoll_wait(efd,&temp,1,-1);
        std::cout<<"检测"<<std::endl;
        
        char buffer[1024];
        // if(temp.events&EPOLLIN)
        // {
        //     read(temp.data.fd,buffer,sizeof(buffer)-1);
        //     epoll_ctl(efd,EPOLL_CTL_ADD|EPOLLET,0,&event);
        // }
        
        if(temp.events&EPOLLOUT)
        {
            if(strlen(buffer)!=0)
            {
                write(temp.data.fd,buffer,strlen(buffer));
            }
            else 
            {
                std::string num = std::to_string(count);
                write(temp.data.fd,num.c_str(),num.size());
                count++;
                epoll_ctl(efd,EPOLL_CTL_ADD|EPOLLET,1,&event1);
                sleep(1);
            }
        }
        printf("%s",buffer);
        memset(buffer,0,sizeof(buffer));
    }
    return 0;
}